<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>如何改变一个Promise实例的状态？</title>
  </head>
  <body>
    <!-- 1、如何改变一个Promise实例的状态？ -->
    <!-- 
            (1)执行resolve（value）：如果当前是pending就会变为fulfilled
            (2)执行reject（reason）：如果当前是pending就会变为rejected
            (3)执行器函数（executor）抛出异常：如果当前是pending就会变为rejected
     -->
    <script>
      const p = new Promise((resolve, reject) => {
        // console.log(a) //引擎抛异常
        // throw 900 //编码抛异常
        // resolve(1)
        throw 900
        console.log(1)
      })
      p.then(
        (value) => {
          console.log('成功', value)
        },
        (reason) => {
          console.log('失败', reason)
        }
      )
    </script>
  </body>
</html>
